<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>展示</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<table class="table">
    <tr>
        <th><input type="checkbox" id="one"></th>
        <th>ID</th>
        <th>广告图片</th>
        <th>广告位置</th>
        <th>广告链接</th>
        <th>广告显示</th>
        <th>操作</th>
    </tr>

    {foreach $data as $k=>$v}
    <tr>
        <th><input type="checkbox" class="two"></th>
        <td>{$v.id}</td>
        <td><img src="{$v.img}" style="width: 60px"></td>
        <td>{$v.location}</td>
        <td>{$v.link}</td>
        <td>{$v.sort}</td>
        <td class="three" id="{$v.status}">{$v.status==1?'√':'x'}</td>
        <td>
            修改
            <button class="btn btn-success" id="{$v.id}" >删除</button>
        </td>
    </tr>
    {/foreach}
</table>
{$data|raw}
</body>
<script src="/static/js/jquery-3.1.1.min.js"></script>
<script>
    $(function () {
        //全选
         $('#one').change(function () {
             var a=$('#one');
             var b=$('.two');
             console.log(a);
             console.log(b);
             for ($i=0;$i<b.length;$i++){
                 if (a[0].checked==true){
                        b[$i].checked=true;
                 }else {
                     b[$i].checked=false;
                 }
             }

//批量删除
             $('button').click(function () {
                 var id=$(this).attr('id');
                 // console.log(id);
                 var status=$('.three').attr('id');
                 console.log(status);
                 $.post(
                     'del',
                     {id:id},
                     function (data) {
                         if (data.code==200){
                             alert('删除成功');
                             location.href='show';
                         }

                     }
                 )
             })

         })
        //异步显示隐藏状态
        // var status=$('.three').attr('id');
        // if (status==1){
        //     $('three').show();
        // }else {
        //     $('three').hide();
        // }

    })
</script>
</html>